package cn.sanch.basic.config;

import cn.sanch.basic.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置类：登录拦截器
 * @author sanch37
 * 2022/6/8
 *
 * Configuration  - 表示当前类是一个配置类 - 替换了xml配置文件
 */
@Configuration
public class MyWebConfig implements WebMvcConfigurer {

    /**
     * 注入自己写的拦截器LoginInterceptor
     *
     * 前提是交给了spring容器管理了
     */
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                //拦截所有请求
                .addPathPatterns("/**")
                //放行登录相关的请求
                .excludePathPatterns("/login/**")
                //放行注册相关的请求 - 手机号注册、邮箱注册、获取手机短信验证码、获取图形验证码、店铺入驻、店铺logo上传
                .excludePathPatterns("/user/*/register","/verifyCode/**","/shop/settlement","/fastdfs/**")
                //放行跟swaggerUI相关的请求
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**")
                //放行邮箱激活
                .excludePathPatterns("/shop/activate/**");
    }
}
